package xyz.wbsite.dbtool.javafx.tool;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;

import java.util.ArrayList;
import java.util.List;

public class ContextMenuBuilder {
    private List<MenuItem> menuItemList = new ArrayList<>();

    public ContextMenuBuilder add(String text, EventHandler<ActionEvent> eventHandler) {
        MenuItem menuItem = new MenuItem(text);
        menuItem.setOnAction(eventHandler);
        menuItemList.add(menuItem);
        return this;
    }

    public ContextMenu build() {
        MenuItem[] menuItems = new MenuItem[menuItemList.size()];
        menuItemList.toArray(menuItems);
        return new ContextMenu(menuItems);
    }
}
